package com.profgj.profgj.service.impl;

import com.profgj.profgj.entity.ProjectImportantDocument;
import com.profgj.profgj.dao.ProjectImportantDocumentDao;
import com.profgj.profgj.service.ProjectImportantDocumentService;
import com.profgj.profgj.vo.ProjectImportantDocumentVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (ProjectImportantDocument)表服务实现类
 *
 * @author makejava
 * @since 2021-06-24 07:54:48
 */
@Service("projectImportantDocumentService")
public class ProjectImportantDocumentServiceImpl implements ProjectImportantDocumentService {
    @Resource
    private ProjectImportantDocumentDao projectImportantDocumentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ProjectImportantDocumentVo queryById(Long id) {
        return this.projectImportantDocumentDao.queryById(id);
    }

    /**
     * 通过ID和用户id 查询单条数据
     *
     * @param id 主键
     * @param userId 用户id
     * @return 实例对象
     */
    @Override
    public ProjectImportantDocumentVo queryByIdAndUserId(Long id,Integer userId) {
        return this.projectImportantDocumentDao.queryByIdAndUserId(id, userId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByLimit(int offset, int limit) {
        return this.projectImportantDocumentDao.queryAllByLimit(offset, limit);
    }


    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @param userId  用户id
     * @return 对象列表
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByUserIdAndLimit(int offset, int limit,Integer userId){
        return this.projectImportantDocumentDao.queryAllByUserIdAndLimit(offset, limit, userId);
    }

    /**
     * 关键字查询多条数据
     * @param word 查询关键字
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByWordLimit(String word, int offset, int limit){
        return this.projectImportantDocumentDao.queryAllByWordLimit(word, offset, limit);
    }

    /**
     * 关键字和用户id查询多条数据
     * @param search 查询关键字
     * @param start 查询起始位置
     * @param length  查询条数
     * @param userId  用户id
     * @return 对象列表
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByWordAndUserIdLimit(String search, int start, int length,Integer userId){
        return this.projectImportantDocumentDao.queryAllByWordAndUserIdLimit(search, start, length, userId);
    }

    /**
     * 新增数据
     *
     * @param projectImportantDocument 实例对象
     * @return 实例对象
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public ProjectImportantDocument insert(ProjectImportantDocument projectImportantDocument) {
        this.projectImportantDocumentDao.insert(projectImportantDocument);
        return projectImportantDocument;
    }

    /**
     * 修改数据
     *
     * @param projectImportantDocument 实例对象
     * @return 实例对象
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public ProjectImportantDocument update(ProjectImportantDocument projectImportantDocument) {
        this.projectImportantDocumentDao.update(projectImportantDocument);
        return this.queryById(projectImportantDocument.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    // 事务隔离级别2 事务传播当是否有事务都开启一个新的事务
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)    // 开启事务
    @Override
    public boolean deleteById(Long id) {
        return this.projectImportantDocumentDao.deleteById(id) > 0;
    }

    /**
     * 关键字和用户id查询
     * @param search
     * @param userId
     * @return
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByWordAndUserId(String search, Integer userId) {
        return this.projectImportantDocumentDao.queryAllByWordAndUserId(search, userId);
    }

    /**
     *  用户id查询项目要件
     * @param userId
     * @return
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByUserId(Integer userId){
        return this.projectImportantDocumentDao.queryAllByUserId(userId);
    }

    /**
     * 用户id 分页查询
     * @param start
     * @param length
     * @param userId
     * @return
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByUserIdLimit(Integer start, Integer length, Integer userId){
        return this.projectImportantDocumentDao.queryAllByUserIdLimit(start, length, userId);
    }

    /**
     * 关键字查询
     * @param search
     * @return
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAllByWord(String search){
        return this.projectImportantDocumentDao.queryAllByWord(search);
    }


    /**
     * 查询所有
     * @return
     */
    @Override
    public List<ProjectImportantDocumentVo> queryAll(){
        return this.projectImportantDocumentDao.queryAll2();
    }
}
